{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "f5186094-8048-4d30-91a1-bb32fbf00bbb",
   "metadata": {},
   "source": [
    "## 南丁格尔圆环图"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d94accc1-af3c-4eb7-8193-629503dfec32",
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "labels = ['[20,30]', '[30,40]', '[40,50]', '>=50']\n",
    "sizes = [37.5, 29.2, 20.8, 12.5]\n",
    "colors = ['#4f46e5', '#9f7aea', '#38bdf8', '#fbbf24']\n",
    "explode = (0.1, 0, 0, 0)  # 突出显示第一个年龄段\n",
    "fig, ax = plt.subplots(figsize=(8, 6), facecolor='#1e293b')\n",
    "ax.set_facecolor('#1e293b')\n",
    "wedges, texts, autotexts = ax.pie(\n",
    "    sizes,\n",
    "    explode=explode,\n",
    "    labels=labels,\n",
    "    autopct='%1.1f%%',\n",
    "    startangle=140,\n",
    "    colors=colors,\n",
    "    wedgeprops=dict(width=0.3, edgecolor='w')\n",
    ")\n",
    "plt.title('2022年上半年各年龄段人数分布\\n公司平均年龄32.5，20-30员工具比例最高占比37.5%', color='white', fontsize=14)\n",
    "\n",
    "for text in texts:\n",
    "    text.set_color(\"white\")\n",
    "for autotext in autotexts:\n",
    "    autotext.set_color(\"white\")\n",
    "plt.rcParams['font.sans-serif'] = ['SimHei']\n",
    "plt.rcParams['axes.unicode_minus'] = False\n",
    "plt.text(-1, -1.2, '数据来源于公司人力资源系统，统计日期截至2022.06.30', color='white', fontsize=10, ha='center')\n",
    "\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3ef181ac-5cc9-4f44-819d-af9487623005",
   "metadata": {},
   "source": [
    "## 仪表盘图"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ab5c9264-c65d-4d1c-a09a-a473c901c282",
   "metadata": {},
   "outputs": [],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "import numpy as np\n",
    "\n",
    "labels = [50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150]\n",
    "sizes = [10] * len(labels)  # The width of each section in degrees\n",
    "colors = ['#1f77b4', '#1f77b4', '#1f77b4', '#1f77b4', '#1f77b4',\n",
    "          '#1f77b4', '#1f77b4', '#1f77b4', '#1f77b4', '#ff7f0e', '#ff7f0e']\n",
    "\n",
    "fig, ax = plt.subplots(figsize=(6, 6), subplot_kw={'projection': 'polar'})\n",
    "ax.set_theta_offset(np.pi / 2)\n",
    "ax.set_theta_direction(-1)\n",
    "\n",
    "bars = ax.bar(np.deg2rad(np.linspace(0, 360, len(labels)+1)[:-1]),\n",
    "              [1] * len(labels),\n",
    "              width=np.deg2rad(sizes),\n",
    "              color=colors,\n",
    "              edgecolor='white',\n",
    "              linewidth=2)\n",
    "\n",
    "ax.set_ylim(0, 1)\n",
    "\n",
    "for i, (bar, label) in enumerate(zip(bars, labels)):\n",
    "    angle = np.deg2rad((i + 0.5) * (360 / len(labels)))\n",
    "    ax.text(angle, 0.5, str(label), ha='center', va='center', color='white')\n",
    "\n",
    "pointer_angle = np.deg2rad(70.2)  # example angle, change it as per your data\n",
    "ax.plot([pointer_angle, pointer_angle], [0, 1], color='gray', linewidth=3)\n",
    "\n",
    "plt.title(\"2022年6月29公司整体运营指数良好\", va='bottom', fontsize=14, color='white', backgroundcolor='#162447')\n",
    "plt.rcParams['font.sans-serif'] = ['SimHei']\n",
    "plt.rcParams['axes.unicode_minus'] = False\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a8ca62f4-aa0f-4837-8fd9-095465e4bd6c",
   "metadata": {},
   "source": [
    "## 目标柱形图"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6012d56e-7f38-4b70-bc1f-c213b32402ee",
   "metadata": {},
   "outputs": [],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "import numpy as np\n",
    "\n",
    "products = ['口红', '面膜', '隔离', '防晒', '精华', '面霜']\n",
    "actual_sales = [653, 523, 648, 856, 714, 785]\n",
    "target_sales = [700, 500, 600, 900, 600, 600]\n",
    "\n",
    "bar_width = 0.35\n",
    "index = np.arange(len(products))\n",
    "\n",
    "fig, ax = plt.subplots(figsize=(10, 6))\n",
    "fig.patch.set_facecolor('#162447')\n",
    "ax.set_facecolor('#162447')\n",
    "\n",
    "bars1 = ax.bar(index - bar_width/2, target_sales, bar_width, label='目标销量', color='white', edgecolor='black')\n",
    "bars2 = ax.bar(index + bar_width/2, actual_sales, bar_width, label='实际销量', color='#1f77b4')\n",
    "\n",
    "for bar in bars1:\n",
    "    ax.text(bar.get_x() + bar.get_width() / 2, bar.get_height() + 10, f'{int(bar.get_height())}', ha='center', color='black', fontsize=10)\n",
    "for bar in bars2:\n",
    "    ax.text(bar.get_x() + bar.get_width() / 2, bar.get_height() + 10, f'{int(bar.get_height())}', ha='center', color='white', fontsize=10)\n",
    "\n",
    "ax.set_title('2022年上半年各商品销量完成情况\\n防晒整体销量最好，达到856，面霜远超目标，超额完成30%', color='white', fontsize=14, pad=20)\n",
    "ax.set_xlabel('*注：数据来源于公司销售系统，统计日期截至2022.06.30', color='white', fontsize=10, loc='right')\n",
    "ax.set_xticks(index)\n",
    "ax.set_xticklabels(products, color='white')\n",
    "ax.set_yticks([])  # Hide y-axis ticks\n",
    "ax.spines['top'].set_visible(False)\n",
    "ax.spines['right'].set_visible(False)\n",
    "ax.spines['bottom'].set_visible(False)\n",
    "ax.spines['left'].set_visible(False)\n",
    "\n",
    "legend = ax.legend(loc='upper left', fontsize=10)\n",
    "plt.setp(legend.get_texts(), color='white')\n",
    "plt.rcParams['font.sans-serif'] = ['SimHei']\n",
    "plt.rcParams['axes.unicode_minus'] = False\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d0bf4216-c67a-42df-a700-9fc0f60c3f02",
   "metadata": {},
   "source": [
    "## 子弹图"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "28048c7e-b98b-403b-8f6e-742152dee44f",
   "metadata": {},
   "outputs": [],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "import numpy as np\n",
    "\n",
    "products = ['口红', '面膜', '隔离', '防晒', '精华', '面霜']\n",
    "actual_sales = [653, 523, 648, 856, 714, 785]\n",
    "target_sales = [700, 500, 600, 900, 600, 600]\n",
    "pass_level = [600] * len(products)     # \"及格\" level\n",
    "good_level = [200] * len(products)     # \"良好\" level\n",
    "excellent_level = [200] * len(products) # \"优秀\" level\n",
    "\n",
    "fig, ax = plt.subplots(figsize=(10, 6))\n",
    "fig.patch.set_facecolor('#162447')\n",
    "ax.set_facecolor('#162447')\n",
    "\n",
    "bar_width = 0.4\n",
    "index = np.arange(len(products))\n",
    "\n",
    "ax.bar(index, pass_level, bar_width, label='及格', color='#0080FF')\n",
    "ax.bar(index, good_level, bar_width, bottom=pass_level, label='良好', color='#00BFFF')\n",
    "ax.bar(index, excellent_level, bar_width, bottom=np.array(pass_level) + np.array(good_level), label='优秀', color='#1E90FF')\n",
    "\n",
    "ax.bar(index, target_sales, bar_width / 4, color='white', label='目标', edgecolor='black', zorder=5)\n",
    "ax.bar(index, actual_sales, bar_width / 4, color='#FFD700', label='实际', edgecolor='black', zorder=5)\n",
    "\n",
    "for i, (actual, target) in enumerate(zip(actual_sales, target_sales)):\n",
    "    ax.text(index[i] - bar_width / 8, target + 30, f'{target}', ha='center', color='black', fontsize=10, zorder=5)\n",
    "    ax.text(index[i] + bar_width / 8, actual + 30, f'{actual}', ha='center', color='black', fontsize=10, zorder=5)\n",
    "\n",
    "ax.set_title('2022年上半年各商品销量完成情况\\n防晒整体销量最好，达到856，面霜远超目标，超额完成30%', color='white', fontsize=14, pad=20)\n",
    "ax.set_xlabel('*注：数据来源于公司销售系统，统计日期截至2022.06.30', color='white', fontsize=10, loc='right')\n",
    "ax.set_xticks(index)\n",
    "ax.set_xticklabels(products, color='white')\n",
    "ax.set_yticks(range(0, 1201, 200))\n",
    "ax.set_yticklabels(range(0, 1201, 200), color='white')\n",
    "\n",
    "legend = ax.legend(loc='upper right', fontsize=10)\n",
    "plt.setp(legend.get_texts(), color='white')\n",
    "plt.rcParams['font.sans-serif'] = ['SimHei']\n",
    "plt.rcParams['axes.unicode_minus'] = False\n",
    "plt.show()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
